package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.common.utils.appkit.FirefightingiotKit;
import com.dataaccess.dataaccess.config.rocketmq.UserProducer;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.annotaion.Action;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.mapper.TestDeviceMapper;
import com.dataaccess.dataaccess.web.service.DeviceAboatGasService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.UUID;

@Action
@RequestMapping("gas")
public class DeviceAboatGasController extends BaseController {
    @Resource
    public MyLogger logger;
    @Resource
    public DeviceAboatGasService deviceAboatGasService;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    UserProducer userProducer;
    /**
     * 回调地址：设备数据变化，订阅后推送设备数据变化通知
     * @param
     * @return
     */
    @At(value = "device/deviceDataChanged", method = RequestMethod.POST)
    public RespEntity deviceDataChanged(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("smokedeviceDataChanged"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("panAnCO");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","gas");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.panAnCO(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * 回调地址：设备数据变化，订阅后推送设备数据变化通知
     * @param
     * @return
     */
    @At(value = "device/siTerWell", method = RequestMethod.POST)
    public RespEntity test(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("gas"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("siTerWell");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","siTerWell");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.siTerWell(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 思维智安可燃气体检测
     * @Date Created in 16:59 2021/7/15
     * @Param [jsonParam]
     */

    @At(value = "device/thinKingZhiAnGas", method = RequestMethod.POST)
    public RespEntity thinKingZhiAnGas(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("thinKingZhiAnGas"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("thinKingZhiAnGas");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","thinKingZhiAnGas");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.thinKingZhiAnGas(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    @Resource
    TestDeviceMapper testDeviceMapper;

    /**
     * @Author YangYu
     * @Description 派安可燃气体（NB8201）
     * @Date Created in 10:51 2022/8/24
     * @Param [jsonParam]
     */

    @At(value = "pnGas", method = RequestMethod.POST)
    public RespEntity pa8201Gas(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("pa8201Gas"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("pa8201Gas");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","pa8201Gas");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.pa8201Gas(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 一氧化碳（吉凯达NB609）
     * @Date Created in 10:51 2022/8/24
     * @Param [jsonParam]
     */

    @At(value = "jikaidaCarbonMonoxide", method = RequestMethod.POST)
    public RespEntity jikaidaCarbonMonoxide(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("jikaidaCarbonMonoxide"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("jikaidaCarbonMonoxide");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","jikaidaCarbonMonoxide");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.jikaidaCarbonMonoxide(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 汉威燃气（JY_KBR2_祥云）
     * @Date Created in 10:51 2022/8/24
     * @Param [jsonParam]
     */

    @At(value = "hanWei_JY_KBR2", method = RequestMethod.POST)
    public RespEntity hanWei_JY_KBR2(@RequestBody(required = false) JSONObject jsonParam){
        logger.info("hanWei_JY_KBR2"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("hanWei_JY_KBR2");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag","hanWei_JY_KBR2");
        String mqFlag = FirefightingiotKit.getStr("mqFlag","mq");
        if(mqFlag.equals("1")){
            return deviceAboatGasService.hanWei_JY_KBR2(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }


    /**
     * @Author YangYu
     * @Description 派安可燃气体（NB8020对接第三方平台）
     * @Date Created in 10:51 2022/8/24
     * @Param [jsonParam]
     */

    @At(value = "pa8020Gas", method = RequestMethod.POST)
    public RespEntity pa8020Gas(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("pa8020Gas"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("pa8020Gas");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return deviceAboatGasService.pa8020Gas(jsonParam);
    }

}
